import React, { LegacyRef } from "react";

interface IProps {}

class CreateRef extends React.Component {
  public domRef: LegacyRef<HTMLDivElement> | undefined;
  constructor(props: IProps) {
    super(props);
    // 一般用于类组件创建ref对象
    // 不要在函数组件中使用 createRef
    this.domRef = React.createRef<HTMLDivElement>();
  }

  componentDidMount(): void {
    console.log(this.domRef);
  }

  render() {
    return <div ref={this.domRef}>createRef</div>;
  }
}

export default CreateRef;
